/**
 * @author ZhiWen Ren
 * @version 1.0
 * @description: LeetCode-279-完全平方数
 * @date 2025/7/28 15:21
 */
public class Solution279 {
    public int numSquares(int n) {
        int[] ans = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j * j <= i; j++) {
                min = Math.min(min, ans[i - j * j]);
            }
            ans[i] = min + 1;
        }
        return ans[n];
    }
}
